package jmu.cyxwcy.librarymanagement.controller;


import jmu.cyxwcy.librarymanagement.pojo.Book;
import jmu.cyxwcy.librarymanagement.pojo.Library;
import jmu.cyxwcy.librarymanagement.pojo.Result;
import jmu.cyxwcy.librarymanagement.pojo.Shelf;
import jmu.cyxwcy.librarymanagement.service.BookService;
import jmu.cyxwcy.librarymanagement.service.ILibraryService;
import jmu.cyxwcy.librarymanagement.service.IShelfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2024-06-23
 */
@RestController
@RequestMapping("/shelf")
public class ShelfController {
    @Autowired
    private IShelfService iShelfService;
    @Autowired
    private BookService bookService;

//   上架
    @PostMapping("/add")
    public Result addShelf(@RequestBody Shelf shelf){
        //新增上架表中的信息
        iShelfService.save(shelf);
        //将书籍表中改为上架
        Book book=new Book();
        book.setBookId(shelf.getBookId());
        book.setStatus("已上架");
        bookService.updateById(book);
        return Result.success();
    }

//    只更改上架的libraryId
    @PutMapping("/update")
    public Result updateShelf(@RequestBody Shelf shelf){
        iShelfService.updateById(shelf);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result deleteShelf(Integer shelfId){
        iShelfService.removeById(shelfId);
        return Result.success();
    }

}
